package com.lst.httpsRequest;

import java.security.MessageDigest;

import org.apache.log4j.Logger;

public class MD5Util {
	protected static Logger log = Logger.getLogger("log");

	public final static String encrypByMd5(String context) {
		StringBuffer buf = new StringBuffer("");
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(context.getBytes("utf-8"));
			byte[] encryContext = md.digest();

			int i;
			for (int offset = 0; offset < encryContext.length; offset++) {
				i = encryContext[offset];
				if (i < 0)
					i += 256;
				if (i < 16)
					buf.append("0");
				buf.append(Integer.toHexString(i));
			}
		} catch (Exception e) {
			log.error(e.getMessage(), e);
		}
		return buf.toString();
	}
}
